"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.getDeviceString = exports.getScreen = exports.getScreenMax = exports.getGlRenderer = exports.getGlRendererRaw = undefined;

var _cache = require("../cache");

var devices = {
    "Apple A7 GPU": {
        1136: ["iPhone 5", "iPhone 5s"],
        2048: ["iPad Air", "iPad Mini 2", "iPad Mini 3"]
    },

    "Apple A8 GPU": {
        1136: ["iPod touch (6th generation)"],
        1334: ["iPhone 6"],
        2001: ["iPhone 6 Plus"],
        2048: ["iPad Air 2", "iPad Mini 4"]
    },

    "Apple A9 GPU": {
        1136: ["iPhone SE"],
        1334: ["iPhone 6s"],
        2001: ["iPhone 6s Plus"],
        2224: ["iPad Pro (9.7-inch)"],
        2732: ["iPad Pro (12.9-inch)"]
    },

    "Apple A10 GPU": {
        1334: ["iPhone 7"],
        2001: ["iPhone 7 Plus"]
    }
};

function getCanvas() {
    return document.createElement('canvas');
}

function getGl() {
    var canvas = getCanvas();
    return canvas && canvas.getContext && canvas.getContext('experimental-webgl');
}

var getGlRendererRaw = exports.getGlRendererRaw = function getGlRendererRaw() {
    var gl = getGl();
    if (!gl || !gl.getExtension) {
        return 'unknown';
    }
    var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
    if (debugInfo == null) {
        return 'unknown';
    }
    return gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
};

var getGlRenderer = exports.getGlRenderer = (0, _cache.cache)(getGlRendererRaw);

var getScreenMax = exports.getScreenMax = function getScreenMax() {
    return Math.max(screen.width, screen.height) * (window.devicePixelRatio || 1);
};
var getScreen = exports.getScreen = function getScreen() {
    var _window$screen = window.screen,
        width = _window$screen.width,
        height = _window$screen.height;

    return [Math.max(width, height), Math.min(width, height), window.devicePixelRatio || 1];
};
var getDeviceString = exports.getDeviceString = function getDeviceString() {
    var glRender = getGlRenderer();
    var screen = getScreen().join('*');
    return [glRender, screen].join(';');
};